*=======================================================*
* JPART 2021, Managing Diversity Differently			*
* Replication code for tables and figures   			*
* Authors: Austin McCrea, Ling Zhu and Morgen Johansen	*
* Last Update by Ling Zhu, July 5,2021					*
*=======================================================*

clear all
use "/Users/lingzhu/Dropbox/Morgen, Ling/Papers/JPART Replication Files/JPART2021MZJ.dta"
xtset ID year

*-----------------------------*
* Table 1. Summary statistics * 
*-----------------------------*
xtreg diversity_tetra herfindahl_final collaboration diversity_pop nonprofit private BSC ///
	general_hosp rural pct_unemployment pct_uninsured i.year, re cluster(ID)
gen sample1=e(sample)

* Full sample
su diversity_tetra DIVERS DIVED DIVQUL DIVTRN herfindahl_final collaboration ///
	diversity_pop nonprofit private BSC general_hosp rural pct_unemployment ///
	pct_uninsured if sample1==1
	
* Subsample, hospitals	
su diversity_tetra DIVERS DIVED DIVQUL DIVTRN herfindahl_final collaboration ///
	diversity_pop nonprofit private BSC general_hosp rural pct_unemployment ///
	pct_uninsured if sample1==1&public==1
	
* Subsample, nonprofit hospitals	
su diversity_tetra DIVERS DIVED DIVQUL DIVTRN herfindahl_final collaboration ///
	diversity_pop nonprofit private BSC general_hosp rural pct_unemployment ///
	pct_uninsured if sample1==1&nonprofit==1

* Subsample, private hospitals
su diversity_tetra DIVERS DIVED DIVQUL DIVTRN herfindahl_final collaboration ///
	diversity_pop nonprofit private BSC general_hosp rural pct_unemployment ///
	pct_uninsured if sample1==1&private==1

*------------------------------*
* Table 2. Models for DMI	   * 
*------------------------------*

* Table 2 Model (1), Random effects panel regression with year fixed effects
xtreg diversity_tetra herfindahl_final collaboration diversity_pop nonprofit ///
	private BSC general_hosp rural pct_unemployment pct_uninsured i.year, ///
	re cluster(ID)
	
* Table 2 Model (2), Random effects panel regression with interaction terms
gen nonprofit_competition=nonprofit*herfindahl_final
gen nonprofit_collaboration=nonprofit*collaboration
gen nonprofit_diversity=nonprofit*diversity_pop

gen private_competition=private*herfindahl_final
gen private_collaboration=private*collaboration
gen private_diversity=private*diversity_pop

gen public_competition=public*herfindahl_final
gen public_collaboration=public*collaboration
gen public_diversity=public*diversity_pop

xtreg diversity_tetra herfindahl_final collaboration diversity_pop ///
nonprofit nonprofit_competition nonprofit_collaboration nonprofit_diversity ///
private private_competition private_collaboration private_diversity ///
BSC general_hosp rural pct_unemployment pct_uninsured i.year, re cluster(ID) 

* Table 2 Model (3), Pooled OLS with interaction terms
reg diversity_tetra herfindahl_final collaboration diversity_pop ///
nonprofit nonprofit_competition nonprofit_collaboration nonprofit_diversity ///
private private_competition private_collaboration private_diversity ///
BSC general_hosp rural pct_unemployment pct_uninsured i.year, cluster(ID) 


*-----------------------------*
* Clarify Code for Figures	  * 
*-----------------------------*

* Figure 1. The effects of competition on DMI by sectors
gen year2012=0
recode year2012 (0=1) if year==2012
estsimp reg diversity_tetra herfindahl_final collaboration diversity_pop ///
nonprofit nonprofit_competition nonprofit_collaboration nonprofit_diversity ///
private private_competition private_collaboration private_diversity ///
BSC general_hosp rural pct_unemployment pct_uninsured year2012, cluster(ID)

generate public_lower=.   
generate public_upper=.
generate public_mean=.

generate nonprofit_lower = .
generate nonprofit_upper = .
generate nonprofit_mean =.

generate private_lower = .
generate private_upper = .
generate private_mean =.

generate vectaxis = .  

recast float vectaxis  	   
local a=0			
local b=1							 
while `a' <= 1{                            
setx herfindahl_final `a' nonprofit 0 private 0 ///
	 collaboration 0.209 diversity_pop 0.390 ///
	 nonprofit_competition 0 nonprofit_collaboration 0 nonprofit_diversity 0 ///
	 private_competition 0 private_collaboration 0 private_diversity 0 ///
	 (BSC general_hosp rural pct_unemployment pct_uninsured year2012) mean ///
	                         					   
simqi, ev genev(p1)       
	_pctile p1, p(2.5, 50, 97.5)      
	display `a'
	replace public_lower = r(r1) in `b'   
	replace public_mean = r(r2) in `b'  
	replace public_upper = r(r3) in `b'  
	  
setx herfindahl_final `a' nonprofit 1 private 0 ///
	 collaboration 0.209 diversity_pop 0.390 ///
	 nonprofit_competition `a'*1 nonprofit_collaboration 0.209*1 nonprofit_diversity 1*0.390 ///
	 private_competition 0 private_collaboration 0 private_diversity 0 ///
	 (BSC general_hosp rural pct_unemployment pct_uninsured year2012) mean ///
						   
simqi, ev genev(p2)        
	_pctile p2, p(2.5, 50, 97.5)      
	display `a'
	replace nonprofit_lower = r(r1) in `b'   
	replace nonprofit_mean = r(r2) in `b'  
	replace nonprofit_upper = r(r3) in `b' 

setx herfindahl_final `a' nonprofit 0 private 1 ///
	 collaboration 0.209 diversity_pop .390 ///
	 (nonprofit_competition nonprofit_collaboration nonprofit_diversity) 0 ///
	 private_competition `a'*1 private_collaboration 0.209*1 private_diversity 0.390*1 ///
	 (BSC general_hosp rural pct_unemployment pct_uninsured year2012) mean ///
						   
simqi, ev genev(p3)        
	_pctile p3, p(2.5, 50, 97.5)      
	display `a'
	replace private_lower = r(r1) in `b'   
	replace private_mean = r(r2) in `b'  
	replace private_upper = r(r3) in `b'
	replace vectaxis = `a' in `b'      
	drop p1
	drop p2
	drop p3
	local a = `a' + 0.1        
	local b=`b'+ 1          
}
*****

*Figure 1. Competition
twoway (rcap public_lower public_upper vectaxis, lcolor(gs12)) /*
	   */ (scatter public_mean vectaxis, mcolor(gs12) msymbol(O)) /*
	   */ (rcap nonprofit_lower nonprofit_upper vectaxis, lcolor(black) lpattern(solid)) /*
	   */ (scatter nonprofit_mean vectaxis, lpattern(solid) mcolor(black) msymbol(d)) /*
	    */ (rcap private_lower private_upper vectaxis, lcolor(gs10) lpattern(vshortdash)) /*
	   */ (scatter private_mean vectaxis, lpattern(solid) mcolor(gs10) msymbol(X)), /*
	   */ ytitle(Predicted Favorability Score) /*
       */ ytitle("Predicted Diversity Management Index Score",size(medsmall)) /*
       */ xtitle("Market Competition", size(medsmall)) /*
	   */ ylabel(0.5(0.1)1, labsize(medsmall)) /* 
       */ xlabel(0(0.1)1, labsize(medsmall))/*
       */ legend(on order( 2 "Public Hospital" /*
       */ 4 "Nonprofit Hospital" 6 "Private Hospital") size(small) lcolor(black) ring(0) position(5)) /* 
       */ yline(0, lpattern(dot) lcolor(red)) /*
       */ scheme(lean1) xsize(10)  ysize(10) /*
       */ name(Competition, replace)	  	   
graph export Competition.pdf, replace

drop b1-b18
drop b19 vectaxis
drop public_lower public_mean public_upper nonprofit_lower nonprofit_mean ///
nonprofit_upper private_lower private_mean private_upper

* Figure 2. The effects of collaboration on DMI by sectors
estsimp reg diversity_tetra herfindahl_final collaboration diversity_pop ///
nonprofit nonprofit_competition nonprofit_collaboration nonprofit_diversity ///
private private_competition private_collaboration private_diversity ///
BSC general_hosp rural pct_unemployment pct_uninsured year2012, cluster(ID)

generate public_lower=.   
generate public_upper=.
generate public_mean=.

generate nonprofit_lower = .
generate nonprofit_upper = .
generate nonprofit_mean =.

generate private_lower = .
generate private_upper = .
generate private_mean =.

generate vectaxis = .  

recast float vectaxis  	   
local a=0			
local b=1							 
while `a' <= 1{                            
setx herfindahl_final 0.276 nonprofit 0 private 0 ///
	 collaboration `a' diversity_pop 0.390 ///
	 nonprofit_competition 0 nonprofit_collaboration 0 nonprofit_diversity 0 ///
	 private_competition 0 private_collaboration 0 private_diversity 0 ///
	 (BSC general_hosp rural pct_unemployment pct_uninsured year2012) mean ///
	                         					   
simqi, ev genev(p1)       
	_pctile p1, p(2.5, 50, 97.5)      
	display `a'
	replace public_lower = r(r1) in `b'   
	replace public_mean = r(r2) in `b'  
	replace public_upper = r(r3) in `b'  
	  
setx herfindahl_final 0.276 nonprofit 1 private 0 ///
	 collaboration `a' diversity_pop .390 ///
	 nonprofit_competition 0.276*1 nonprofit_collaboration `a'*1 nonprofit_diversity 1*0.390 ///
	 private_competition 0 private_collaboration 0 private_diversity 0 ///
	 (BSC general_hosp rural pct_unemployment pct_uninsured year2012) mean ///
						   
simqi, ev genev(p2)        
	_pctile p2, p(2.5, 50, 97.5)      
	display `a'
	replace nonprofit_lower = r(r1) in `b'   
	replace nonprofit_mean = r(r2) in `b'  
	replace nonprofit_upper = r(r3) in `b' 

setx herfindahl_final 0.276 nonprofit 0 private 1 ///
	 collaboration `a' diversity_pop .390 ///
	 (nonprofit_competition nonprofit_collaboration nonprofit_diversity) 0 ///
	 private_competition 0.276*1 private_collaboration `a'*1 private_diversity 0.390*1 ///
	 (BSC general_hosp rural pct_unemployment pct_uninsured year2012) mean ///
						   
simqi, ev genev(p3)        
	_pctile p3, p(2.5, 50, 97.5)      
	display `a'
	replace private_lower = r(r1) in `b'   
	replace private_mean = r(r2) in `b'  
	replace private_upper = r(r3) in `b'
	replace vectaxis = `a' in `b'      
	drop p1
	drop p2
	drop p3
	local a = `a' + 0.1        
	local b=`b'+ 1          
}
*****

*Figure 2. Collaboration
twoway (rcap public_lower public_upper vectaxis, lcolor(gs12) msymbol(O)) /*
	   */ (scatter public_mean vectaxis, mcolor(gs12)) /*
	   */ (rcap nonprofit_lower nonprofit_upper vectaxis, lcolor(black) lpattern(s)) /*
	   */ (scatter nonprofit_mean vectaxis, lpattern(solid) mcolor(black) msymbol(d)) /*
	   */ (rcap private_lower private_upper vectaxis, lcolor(gs12) lpattern(vshortdash)) /*
	   */ (scatter private_mean vectaxis, lpattern(solid) mcolor(gs12) msymbol(X)), /*
	   */ ytitle(Predicted Favorability Score) /*
       */ ytitle("Predicted Diversity Management Index Score",size(medsmall)) /*
       */ xtitle("Inter-Hospital Collaboration", size(medsmall)) /*
	   */ ylabel(0.5(0.1)1, labsize(medsmall)) /* 
       */ xlabel(0(0.1)1, labsize(medsmall))/*
       */ legend(on order( 2 "Public Hospital" /*
       */ 4 "Nonprofit Hospital" 6 "Private Hospital") size(small) lcolor(black) ring(0) position(5)) /* 
       */ yline(0, lpattern(dot) lcolor(red)) /*
       */ scheme(lean1) xsize(10)  ysize(10) /*
       */ name(Collaboration, replace)	  	   
graph export collaboration.pdf, replace

drop b1-b18
drop b19 vectaxis
drop public_lower public_mean public_upper nonprofit_lower nonprofit_mean ///
nonprofit_upper private_lower private_mean private_upper


* Figure 3. The effects of diversity on DMI by sectors
estsimp reg diversity_tetra herfindahl_final collaboration diversity_pop ///
nonprofit nonprofit_competition nonprofit_collaboration nonprofit_diversity ///
private private_competition private_collaboration private_diversity ///
BSC general_hosp rural pct_unemployment pct_uninsured year2012, cluster(ID)

generate public_lower=.   
generate public_upper=.
generate public_mean=.

generate nonprofit_lower = .
generate nonprofit_upper = .
generate nonprofit_mean =.

generate private_lower = .
generate private_upper = .
generate private_mean =.

generate vectaxis = .  

recast float vectaxis  	   
local a=0			
local b=1							 
while `a' <= 1{                            
setx herfindahl_final 0.276 nonprofit 0 private 0 ///
	 collaboration 0.209 diversity_pop `a' ///
	 nonprofit_competition 0 nonprofit_collaboration 0 nonprofit_diversity 0 ///
	 private_competition 0 private_collaboration 0 private_diversity 0 ///
	 (BSC general_hosp rural pct_unemployment pct_uninsured year2012) mean ///
	                         					   
simqi, ev genev(p1)       
	_pctile p1, p(2.5, 50, 97.5)      
	display `a'
	replace public_lower = r(r1) in `b'   
	replace public_mean = r(r2) in `b'  
	replace public_upper = r(r3) in `b'  
	  
setx herfindahl_final 0.276 nonprofit 1 private 0 ///
	 collaboration 0.209 diversity_pop `a' ///
	 nonprofit_competition 0.276*1 nonprofit_collaboration 0.209*1 nonprofit_diversity 1*`a' ///
	 private_competition 0 private_collaboration 0 private_diversity 0 ///
	 (BSC general_hosp rural pct_unemployment pct_uninsured year2012) mean ///
						   
simqi, ev genev(p2)        
	_pctile p2, p(2.5, 50, 97.5)      
	display `a'
	replace nonprofit_lower = r(r1) in `b'   
	replace nonprofit_mean = r(r2) in `b'  
	replace nonprofit_upper = r(r3) in `b' 

setx herfindahl_final 0.276 nonprofit 0 private 1 ///
	 collaboration 0.209 diversity_pop `a' ///
	 (nonprofit_competition nonprofit_collaboration nonprofit_diversity) 0 ///
	 private_competition 0.276*1 private_collaboration 0.209*1 private_diversity `a'*1 ///
	 (BSC general_hosp rural pct_unemployment pct_uninsured year2012) mean ///
						   
simqi, ev genev(p3)        
	_pctile p3, p(2.5, 50, 97.5)      
	display `a'
	replace private_lower = r(r1) in `b'   
	replace private_mean = r(r2) in `b'  
	replace private_upper = r(r3) in `b'
	replace vectaxis = `a' in `b'      
	drop p1
	drop p2
	drop p3
	local a = `a' + 0.1        
	local b=`b'+ 1          
}
*****

*Figure 3. Diversity
twoway (rcap public_lower public_upper vectaxis, lcolor(gs12)) /*
	   */ (scatter public_mean vectaxis, mcolor(gs12) msymbol(O)) /*
	   */ (rcap nonprofit_lower nonprofit_upper vectaxis, lcolor(black) lpattern(solid)) /*
	   */ (scatter nonprofit_mean vectaxis, lpattern(solid) mcolor(black) msymbol(d)) /*
	    */ (rcap private_lower private_upper vectaxis, lcolor(gs10) lpattern(vshortdash)) /*
	   */ (scatter private_mean vectaxis, lpattern(solid) mcolor(gs10) msymbol(X)), /*
	   */ ytitle(Predicted Favorability Score) /*
       */ ytitle("Predicted Diversity Management Index Score",size(medsmall)) /*
       */ xtitle("Racial Diversity of County Population", size(medsmall)) /*
	   */ ylabel(0.5(0.1)1, labsize(medsmall)) /* 
       */ xlabel(0(0.1)1, labsize(medsmall))/*
       */ legend(on order( 2 "Public Hospital" /*
       */ 4 "Nonprofit Hospital" 6 "Private Hospital") size(small) lcolor(black) ring(0) position(5)) /* 
       */ yline(0, lpattern(dot) lcolor(red)) /*
       */ scheme(lean1) xsize(10)  ysize(10) /*
       */ name(Diversity, replace)	  	   
graph export Diversity.pdf, replace

drop b1-b18
drop b19 vectaxis
drop public_lower public_mean public_upper nonprofit_lower nonprofit_mean ///
nonprofit_upper private_lower private_mean private_upper


*------------------------------*
* Table 3 Split sample analysis* 	
*------------------------------*

* Table 3 Model (4)
xtreg diversity_tetra herfindahl_final collaboration diversity_pop BSC ///
	general_hosp rural pct_unemployment pct_uninsured i.year if public==1, re cluster(ID)

* Table 3 Model (5)
xtreg diversity_tetra herfindahl_final collaboration diversity_pop BSC ///
	general_hosp rural pct_unemployment pct_uninsured i.year if nonprofit==2, re cluster(ID)

* Table 3 Model (6)
xtreg diversity_tetra herfindahl_final collaboration diversity_pop BSC ///
	general_hosp rural pct_unemployment pct_uninsured i.year if private==3, re cluster(ID)
	
*------------------------------*
* Table 4 Panel Logit Models   * 	
*------------------------------*
* Table 4 Model (7)
xtlogit DIVERS herfindahl_final collaboration diversity_pop BSC general_hosp rural ///
	pct_unemployment pct_uninsured i.year if public ==1, or vce(cluster ID)

* Table 4 Model (8)
xtlogit DIVERS herfindahl_final collaboration diversity_pop BSC general_hosp rural ///
	pct_unemployment pct_uninsured i.year if nonprofit ==1, or vce(cluster ID)

* Table 4 Model (9)
xtlogit DIVERS herfindahl_final collaboration diversity_pop BSC general_hosp rural ///
	pct_unemployment pct_uninsured i.year if private ==1, or vce(cluster ID)

*------------------------------*
* Table 5 Robustnese Checks	   * 	
*------------------------------*

* Table 5 Model (10) fixed effects LPM
xtreg DIVERS herfindahl_final collaboration diversity_pop ///
nonprofit nonprofit_competition nonprofit_collaboration nonprofit_diversity ///
private private_competition private_collaboration private_diversity ///
BSC general_hosp rural pct_unemployment pct_uninsured,fe 

* Table 5 Model (11) random effects panel logistic regression
xtlogit DIVERS herfindahl_final collaboration diversity_pop ///
nonprofit nonprofit_competition nonprofit_collaboration nonprofit_diversity ///
private private_competition private_collaboration private_diversity ///
BSC general_hosp rural pct_unemployment pct_uninsured, re or

* Table 5 Model (12) population average panel logistic regression
xtlogit DIVERS herfindahl_final collaboration diversity_pop ///
nonprofit nonprofit_competition nonprofit_collaboration nonprofit_diversity ///
private private_competition private_collaboration private_diversity ///
BSC general_hosp rural pct_unemployment pct_uninsured, pa or
